<?php

namespace App\Admin\Controllers\Core;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\File;

class UploadController extends Controller
{
    /**
     * Notes   : 编辑器图片文件上传
     *
     * @Date   : 2024/8/12 下午6:06
     * @Author : <Jason.C>
     * @param  Request  $request
     * @return array
     */
    public function editor(Request $request): array
    {
        $file = $request->file('file');
        $hash = File::hash($file);
        $filename = $hash.'.'.$file->getClientOriginalExtension();
        $dir = date('Y/m/d');
        $disk = $request->application->domainPool->storage(true);
        $disk->putFileAs($dir, $file, $filename);

        return [
            'location' => $disk->url("$dir/$filename"),
        ];
    }
}
